package com.base.controller;

import com.base.po.voip.Statistics;
import com.base.service.*;
import com.base.utils.Produce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据统计
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class index_Statistics {
	@Autowired
	private SubscribersService subscribersService; 
	@Autowired
	private RewardsService rewardsService; // 任务信息
	@Autowired
	private UsersService usersService; // 任务信息
	@Autowired
	private CallbackinfoesService callbackinfoesService; // 电话信息
	@Autowired
	private PayinfoesService payinfoesService; // 支付信息
	@Autowired
	private WithdrawalsService withdrawalsService;

	/**
	 * 首页
	 *
	 * @return ModelAndView
	 * @throws Exception
	 */
	@RequestMapping("/statisticsIndex")
	public ModelAndView statisticsIndex(HttpServletRequest request) throws Exception {
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
		if (userid == null) return new ModelAndView("jsp/loginCheck"); // 未登录
		Map<String, Object> map = new HashMap<>(); // 存储数据对象
		// 设置分页 获取内容
		List<Statistics> statisticsList = new ArrayList<>();

		Statistics statistics = null;
		Integer type = 0;
		BigDecimal statisticsNum = new BigDecimal(0);
		String statisticsName = "";
		for (int i = 0; i < 8; i++){
			statistics = new Statistics();
			switch (i){
				case 0:
					type = 1;
					statisticsName = "注册人数";
					statisticsNum = new BigDecimal(subscribersService.selectByCount(userid, null, null));
					break;
				case 1:
					type = 2;
					statisticsName = "总充值数";
					statisticsNum = new BigDecimal(payinfoesService.countDay(userid, null, null));
					break;
				case 2:
					type = 3;
					statisticsName = "充值金额";
					statisticsNum = payinfoesService.selectAllMoney(userid, null, null);
					break;
				case 3:
					type = 4;
					statisticsName = "提现金额";
					statisticsNum = withdrawalsService.selectAllMoney(userid, null, null);
					break;
				case 4:
					type = 5;
					statisticsName = "今日注册人数";
					statisticsNum = new BigDecimal(subscribersService.selectByCount(userid, Parameters.getDayBegin(), Parameters.getDayEnd()));
					break;
				case 5:
					type = 6;
					statisticsName = "今日总充值数";
					statisticsNum = new BigDecimal(payinfoesService.countDay(userid, Parameters.getDayBegin(), Parameters.getDayEnd()));
					break;
				case 6:
					type = 7;
					statisticsName = "今日充值金额";
					statisticsNum = payinfoesService.selectAllMoney(userid, Parameters.getDayBegin(), Parameters.getDayEnd());
					break;
				case 7:
					type = 8;
					statisticsName = "今日提现金额";
					statisticsNum = withdrawalsService.selectAllMoney(userid, Parameters.getDayBegin(), Parameters.getDayEnd());
					break;
				default:
					break;
			}

			statistics.setType(type);
			statistics.setStatisticsName(statisticsName);
			statistics.setStatisticsNum(statisticsNum);
			statistics.setParentId(userid);
			statisticsList.add(statistics);
		}

		map.put("statisticsList", statisticsList);

		return new ModelAndView("jsp/index_Statistics", map);
	}
}
